<?php


###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

$pageid = $params['page_id'];
$templateid = $params['template_id'];

$page = JFX_Block::getBlockById($pageid, $pageid);
$pageDetails = json_decode($page->__toJson());
$pageDetails->action_buttons = $THEME->getPageActionButtons(preg_replace('/[^0-9]/', '', $pageid));
$pageDetails = json_encode($pageDetails);
$workspaceId = $SETTINGS->get('live_workspace_id');

$js = <<<JS

var AdminBlocks;

$(document).ready(function(){
    var parms = {
        pageid : '{$pageid}',
        workspaceid : '{$workspaceId}',
        templateid : '{$templateid}',
        pageDetails : {$pageDetails},
        mode : 'template',
        templatePageId : '{$SETTINGS->get('template_page_id')}'
    }

    AdminBlocks = new JFX_AdminBlocks(parms);
    //AdminBlocks.initBlocks('{$pageid}', '{$workspaceId}', '{$templateid}', {$pageDetails}, 'template', '{$SETTINGS->get('template_page_id')}');
	AdminBlocks.initMenu('{$pageid}');


    AdminBlocks.getMenuContent("jfx-toolbar");

    //$('#jfx-leftcol-menu-abs').hover(JFXLeftColShow, JFXLeftColHide);


    $('#jfx-toggle-actions').click(function(){
        if($(this).attr('visible') == 'visible'){
            // hide it
            $('.jfx-actions').slideUp();
            $(this).attr('visible', 'hidden');
            $('img', this).attr('src', $('img', this).attr('src').replace('up', 'down'));
            $('span', this).html('Show Actions');
            if(AdminBlocks.visibleActions){
                $(AdminBlocks.visibleActions).css('display', 'none');
                AdminBlocks.visibleActions = null;
            }
        }else{
            // show it
            $('.jfx-actions').slideDown();
            $(this).attr('visible', 'visible');
            $('img', this).attr('src', $('img', this).attr('src').replace('down', 'up'));
            $('span', this).html('Hide Actions');
        }
    });

    $('#insert-menu-close-button').hover(function(){
        $('img', this).attr('src', $('img', this).attr('src').replace('normal', 'hover'));
    }, function(){
        $('img', this).attr('src', $('img', this).attr('src').replace('hover', 'normal'));
    });

    $('#insert-menu-close-button').click(function(){
        AdminBlocks.hideInsertMenu(this.parentNode, this);
    });

    $('#jfx-full-screen-button').click(function(){
        AdminBlocks.toggleFullScreen();
    });

});

JS;


$VIEW->addJs($js);

